package day04;

import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;

public class SwitchDemo {
    public static void main(String[] args) {
//      2

        // int a=new Random(int);
//        Scanner sc=new Scanner(System.in);
//        System.out.println("请输入:");
//        int age=sc.nextInt();
//        System.out.println(age);
//        sc.reset();

//        System.out.println(age);
        Scanner in;
        Scanner sc = new Scanner(System.in);
        int i;
        while (true) {
            in = new Scanner(System.in);
            while (true) {
                try {
                    System.out.print("Enter an integer number: ");
                    i = in.nextInt();
                    System.out.print("Thanks, you entered: ");
                    System.out.println(i);
                    //InputMismatchException ex
                } catch (InputMismatchException ex) {
                    System.out.println("输入有误,重新输入:");
                    //in.reset();
                    break;

                    // throw ex;
                } catch (NumberFormatException e) {
                    System.out.println("s数据格式异常:");
                    continue;
                }
                //// <----------------------------- [The reset is here]
//            finally {
//                System.out.println("到最后");
//                int i = in.nextInt();
//                System.out.print("Thanks, you entered: ");
//                System.out.println(i);
//            }
            }
        }
    }

}
